package com.wallet.my.controller;

import com.wallet.my.controller.model.LoginRequest;
import com.wallet.my.controller.model.RegisterRequest;
import com.wallet.my.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 用户登录，注册接口
 */
@RestController
@RequestMapping("/Api")
public class UserController {
    @Autowired
    private UserService userService;

//注册用户
    @PostMapping("/register")
    public Map<String, Object> register(@RequestBody RegisterRequest registerRequest){
        return userService.register(registerRequest);
    }

//    用户登录
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody LoginRequest loginRequest, HttpSession httpSession) {
        httpSession.setAttribute("username", loginRequest.getUsername());
        return userService.login(loginRequest);
    }
}
